package com.seanchenxi.gwt.wordpress.json.service.util;

import java.util.ArrayList;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;

public class JsUtil {
	
	@SuppressWarnings("unchecked")
	public static <M> ArrayList<M> convert(JsArray<? extends JavaScriptObject> jsList) {
		if(jsList == null || jsList.length() < 1) 
			return new ArrayList<M>();
		ArrayList<M> list = new ArrayList<M>(jsList.length());
		for (int i = 0; i < jsList.length(); i++) {
			try{
				list.add((M)jsList.get(i));
			}catch (Exception e) {
			}	
		}
		return list;
	}
}
